/**
 * getId 构造函数中有用勿删
 */

function getId(id) {
  return document.getElementById(id);
}

/**
 * 锚点跳转平滑过度
 */
function dwei(id) {
  var i = $(id).offset().top;
  $("html, body").animate({
    scrollTop: i + "px"
  }, 600);
}

/**
 * 设置单页轮播图中位置偏移至居中
 * id = fullPic
 */

function setFullPicPos() {
  var clientWidth = document.documentElement.clientWidth;
  var left = (1920 - clientWidth) / 2;
  $('#fullPic').css('margin-left', -left + 'px');
}
setFullPicPos();
window.onresize = function () {
  setFullPicPos();
}

/**
 * 获取单页中品牌信息 填写地址内容
 */

function getBrand() {
  this.init();

  this.brname = getId('brName');
  this.brfoot = getId('brandName');
  if (this.brname) {
    if (this.isSet(this.brname.innerText, /auto/)) {
      this.brname.innerText = ' “' + this.cate() + '” ';
    }
  }
  if (this.brfoot) {
    if (this.isSet($('#brandName').text(), /auto/)) {
      this.brfoot.innerText = '<span>版权所有&copy;</span>  ' + this.address();
      $('#brandName').text('<span>版权所有&copy;</span>  ' + this.address());
    }
  }
}

getBrand.constructor = getBrand;

getBrand.prototype = {
  init: function () {
    /**
     * [h1 顶部公司信息栏]
     * @type {[type]}
     * 获取公司名称公司地址等数据
     */
    this.h1 = document.getElementsByTagName('h1')[0];
    if (this.h1) {
      this.temp = this.h1.innerText.split(/_|，|,/g);
      this.brandName = this.temp[0];
      this.brandCate = this.temp[1];
      this.brandAddress = this.temp[this.temp.length - 1];
    }
  },
  isSet: function (txt, reg) {
    return reg.exec(txt);
  },
  name: function () {
    return this.brandName;
  },
  cate: function () {
    return this.brandCate;
  },
  address: function () {
    return this.brandAddress;
  }
}

var getBrandData = new getBrand();

/**
 * set user info
 */
$(function () {
  if (typeof udata === 'object') {
    $.each(udata, function (key, val) {
      if (key === 'qq') {
        $('.contacts-user-info .' + key).attr('href', 'http://wpa.qq.com/msgrd?v=3&uin=' + val + '&site=qq&menu=yes');
        if ($('.contacts-user-info .' + key + ' img').get(0)) {
          $('.contacts-user-info .' + key + ' img').attr('src', 'http://wpa.qq.com/pa?p=2:' + val + ':41 &r=0.2467497322281375');
        } else {
          var img = $('<img />');
          img.attr('src', 'http://wpa.qq.com/pa?p=2:' + val + ':41 &r=0.2467497322281375');
          $('.contacts-user-info .' + key).append(img);
        }
      }else if (key === 'qq2') {
        $('.contacts-user-info .' + key).attr('href', 'http://wpa.qq.com/msgrd?v=3&uin=' + val + '&site=qq&menu=yes');
        if ($('.contacts-user-info .' + key + ' img').get(0)) {
          $('.contacts-user-info .' + key + ' img').attr('src', 'http://wpa.qq.com/pa?p=1:' + val + ':4');
        } else {
          var img = $('<img />');
          img.attr('src', 'http://wpa.qq.com/pa?p=1:' + val + ':4');
          $('.contacts-user-info .' + key).append(img);
        }
      } else if (key === 'website') {
        var site;
        //setHref
        if (val[0].indexOf('http') !== null && val[1]) {
          site = val[0].substring(val[0].indexOf('//') + 2, val[0].length);
        } else {
          site = val[0];
        }
        $('.contacts-user-info .' + key).attr('href', val[0])

        //isHideText
        if (val[2] !== 'none') {
          $('.contacts-user-info .' + key).text(site);
        }
      } else {
        $('.contacts-user-info .' + key).text(val);
      }
    })
  }
})